define(function () {
    var $user = $('.user-name');
    var $password = $('.pass-word');
    var $login = $('.logging');
    var $form = $('#fm1');
    var wrap = $(".third-part");
    var regMob = /^\d{11}$/;
    var mloginurl = $('#mloginurl');
    var mobile_auth = $(".mobile-auth");
    var $gps = $("#gps");

    function init() {
        $user.bind('keyup', function (evt) {
            var et = evt || window.event;
            inputFocus(et);
        });

        $user.bind('blur', function (evt) {
            if (regMob.test($user.val())) {
                asyQuery({
                    url: CFG.API_URL + "account/mobileservice?action=mobileIsBound",
                    data: {
                        umobile: $user.val()
                    },
                    success: function (dt) {
                        if (dt.status) {
                            mloginurl.attr("href", CFG.API_URL + "account/login_mobile_verification_code?umobile=" + $user.val());
                            mobile_auth.show();
                        } else {
                            mloginurl.attr("href", "");
                            mobile_auth.hide();
                        }
                    }
                });
            }
        });

        $password.bind('keyup', function (evt) {
            var et = evt || window.event;
            inputFocus(et);
        });

        $login.bind('click', function () {
            if ($user.val() == '') {
                alert("用户名不能为空,请填写完整!");
            }else if ($password.val() == '') {
                alert("密码不能为空,请您填写完整!");
            }else {
                $form.submit();
            }
        });

        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(function (position) {
                $gps.val(position.coords.latitude + "," + position.coords.longitude)
            }, function () {
                console.log("无法获取用户信息");
            });
        }

    }

      showMoreBtn.bind("click",function(){
          wrap.toggleClass("third-part-new");
          return false;
      });


    function inputFocus(et) {
        var keyCode = et.keyCode;

        if (keyCode == 13) {
            if ($user.val() == '') {
                $user.get(0).focus();
            }
            else if ($password.val() == '') {
                $password.get(0).focus();
            }
            else {
                $form.submit();
            }
        }
    }

    asyQuery = function (conf) {
        return $.ajax({
            url: conf.url,
            type: conf.type || 'GET',
            data: conf.data || {},
            dataType: 'json',
            success: function (dt) {
                if (typeof conf.success === "function") {
                    conf.success(dt);
                }
            }
        });
    };

    return {
        init: init
    }
});